package cn.jbolt.meinvtu.photo;


import java.util.List;

import com.jfinal.plugin.activerecord.Db;

import cn.jbolt.meinvtu.common.model.Photo;

public class PhotoService {
	public List<Photo> getByAlbum(Integer albumId) {
		return Photo.dao.find("select * from photo where albumId=?",albumId);
	}
	public int getPrevId(Integer albumId, Integer id) {
		List<Integer> ids=Db.query("select id from photo where albumId=?",albumId);
		for(int i=0;i<ids.size();i++){
			if(i>=1&&id.intValue()==ids.get(i).intValue()){
				return ids.get(i-1);
			}
		}
		return 0;
	}
	public int getNextId(Integer albumId, Integer id) {
		List<Integer> ids=Db.query("select id from  photo where albumId=?",albumId);
		for(int i=0;i<ids.size();i++){
			if(i<ids.size()-1&&id.intValue()==ids.get(i).intValue()){
				return ids.get(i+1);
			}
		}
		return 0;
	}
	public void deleteAll() {
		Db.delete("delete from photo");
		
	}
	public List<Photo> getAllList() {
		return Photo.dao.find("select * from photo");
	}
	public void deleteByMeinvId(Integer meinvId) {
	   Db.delete("delete from photo where meinvId=?",meinvId);
	}

}
